//package top.rushpeak.edu03.admin.util;
//
//import java.io.StringWriter;
//import java.util.ArrayList;
//import java.util.Arrays;
//
//import org.apache.log4j.Logger;
//import org.apache.velocity.Template;
//import org.apache.velocity.VelocityContext;
//import org.apache.velocity.app.VelocityEngine;
//import org.apache.velocity.runtime.RuntimeConstants;
//import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;
//
//import top.rushpeak.edu03.admin.pojo.TableColum;
//import top.rushpeak.edu03.admin.pojo.TableColumMapping;
//
//
//public class VelocityUtil {
//	
//	private static final Logger	LOG	= Logger.getLogger(VelocityUtil.class);
//	
//	private static VelocityEngine getVelocityEngine() {
//		VelocityEngine ve = new VelocityEngine();
//		ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
//		ve.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
//		ve.setProperty("input.encoding", "UTF-8");
//		ve.setProperty("output.encoding", "UTF-8");
//		ve.init();
//		return ve;
//	}
//	
////	public static String exportContent(String templateName, VelocityContext context)
////																					throws Exception {
////		
////		VelocityEngine ve = getVelocityEngine();
////		
////		final String templatePath = "templates/" + templateName;
////		
////		LOG.info(templatePath);
////		
////		InputStream input = VelocityUtil.class.getClassLoader().getResourceAsStream(templatePath);
////		if (input == null) {
////			throw new IOException("Template file doesn't exist");
////		}
////		
////		InputStreamReader reader = new InputStreamReader(input, "UTF-8");
////		
////		StringWriter writer = new StringWriter();
////		
////		if (!ve.evaluate(context, writer, templatePath, reader)) {
////			throw new Exception("Failed to convert the template into html.");
////		}
////		
////		//		template.merge(context, writer);
////		
////		writer.flush();
////		writer.close();
////		
////		return writer.toString();
////	}
////	
//	
//	public static String exportHtmlContent(TableColumMapping table) throws Exception{
//		
//
//		VelocityEngine ve = getVelocityEngine();
//		
//		String templatePath = "templates/htmlAjax.vm" ;
//		Template template = ve.getTemplate(templatePath);
//		VelocityContext velocityContext = new VelocityContext();
//		velocityContext.put("table", table);
//		StringWriter stringWriter = new StringWriter();
//		template.merge(velocityContext, stringWriter);
//		
//		stringWriter.flush();
//		stringWriter.close();
//		
//		System.out.println("-------------html--code-----------------");
//		System.out.println(stringWriter.toString());
//		
//		return stringWriter.toString();
//	}
//	
//	public static String exportJavaContent(TableColumMapping table) throws Exception{
//		
//
//		VelocityEngine ve = getVelocityEngine();
//		
//		String templatePath = "templates/javacodeAjax.vm" ;
//		Template template = ve.getTemplate(templatePath);
//		VelocityContext velocityContext = new VelocityContext();
//		velocityContext.put("table", table);
//		StringWriter stringWriter = new StringWriter();
//		template.merge(velocityContext, stringWriter);
//		
//		stringWriter.flush();
//		stringWriter.close();
//		
//		System.out.println("-------------java--code-----------------");
//		System.out.println(stringWriter.toString());
//		
//		return stringWriter.toString();
//	}
//	
//	
//	public static void main(String[] args) throws Exception {
//		
////		System.out.println(VelocityUtil.exportContent("result.vm", new VelocityContext()));
//		
//		//构造对象
//		TableColumMapping table = new TableColumMapping();
//		table.setMethodName("testTable");
//		table.setTableName("test_table");
//		table.setTableNameRemak("自动创建测试");
//		TableColum id = new TableColum("id","ID");
//		TableColum name = new TableColum("name","用户名");
//		TableColum birth = new TableColum("date","birth","生日");
//		TableColum updateTime = new TableColum("datetime","updateTime","时间秒");
//		
//		table.setAddColums(new ArrayList<TableColum>(Arrays.asList(
//				name,
//				birth,
//				updateTime
//		)));
//		table.setUpdateColums(new ArrayList<TableColum>(Arrays.asList(
//				name,
//				birth,
//				updateTime
//		)));
//		table.setSearchColums(new ArrayList<TableColum>(Arrays.asList(
//				name,
//				birth,
//				updateTime
//		)));
//		table.setListColums(new ArrayList<TableColum>(Arrays.asList(
//				id,
//				name,
//				birth,
//				updateTime
//		)));
//		//html
//		exportHtmlContent(table);
//		//java
//		exportJavaContent(table);
//		
//	}
//}
